package org.bao.pet.utils;

import java.io.File;

public class FileSystem {
	public static final String NEW_DIRECTORY_NAME_DEFAULT = "RESIZED";
	
	//registered valid image format.
	public static final String VALID_IMAGE_FORMAT_JPG = "JPG";
	public static final String VALID_IMAGE_FORMAT_GIF = "GIF";
	public static final String VALID_IMAGE_FORMAT_BMP = "BMP";
	public static final String VALID_IMAGE_FORMAT_PNG = "PNG";
	
	public static boolean isValidImageFile(String filepath){
		String suffix = filepath.substring(filepath.lastIndexOf(".") + 1, filepath.length()).toUpperCase();
		
		if(suffix.equals(VALID_IMAGE_FORMAT_BMP) || suffix.equals(VALID_IMAGE_FORMAT_GIF)
				|| suffix.equals(VALID_IMAGE_FORMAT_JPG) || suffix.equals(VALID_IMAGE_FORMAT_PNG)){
			return true;
		}
		else{
			return false;
		}
	}
	
	public static String getUpperDirectory(String filepath){
		String path = filepath.substring(0,filepath.lastIndexOf(PlatformInfo.getInstance().get(PlatformInfo.INFO_TYPE_SEPARATOR)));
		
		//System.out.println(path);
		
		return path;
	}
	
	public static File createDirectory(File parent,String name){
		if(parent.isDirectory()){
			String newDir = parent.getAbsolutePath() + PlatformInfo.getInstance().get(PlatformInfo.INFO_TYPE_SEPARATOR) + name;
			
			//System.out.println(newDir);
			
			File dir = new File(newDir);
			
			if(!dir.exists()){
				dir.mkdir();
			}
			else{
				//System.err.println(dir);
			}
			
			return dir;
		}
		
		return null;
	}
	
	public static String generateNewFileName(String filepath){
		String original = filepath.substring(filepath.lastIndexOf(PlatformInfo.getInstance().get(PlatformInfo.INFO_TYPE_SEPARATOR)) + 1,filepath.length());
		
		//System.out.println(original);
		
		return "edited_" + original;
	}
}
